const data = {
    b: {
        c: '1',
        d: {
            e: 2
        },
        f: [
            {g: 1},
            [
                "5",
                "6",
                {
                    'h': [7, 8, 9]
                }
            ],
            1
        ]
    }
}

function recursionData(data) {
    const arr = [];
    const keys = Object.keys(data);
    const values = Object.values(data);
    keys.forEach((item, index) => {
        let type = typeof values[index];
        const params = {
            name: item,
            value: typeof values[index] !== 'object' ? values[index] : undefined,
            open: false,
            type: type,
            children: typeof values[index] === 'object' ? recursionData(values[index]) : undefined
        }
        if (Object.prototype.toString.call(values[index]) === '[object Object]') {
            params.type = 'object';
        } else if (Object.prototype.toString.call(values[index]) === '[object Array]') {
            params.type = 'array';
        }
        arr.push(params);
    });
    return arr;
}

const fuza = recursionData(data)
console.log(JSON.stringify(fuza));

function* createIterator(obj) {
    for (let value in obj) {
        yield obj[value];
    }
}

function treeRevers(tree) {
    const types = ['string', 'number', 'boolean'];
    let obj = {}
    tree.forEach(i => {
        if (types.includes(i.type)) {
            obj[i.name] = i.value
        }
        if (i.type === 'array') {
            let iterator = createIterator(treeRevers(i.children))
            obj[i.name] = Array.from(iterator)
        }
        if (i.type === 'object') {
            obj[i.name] = treeRevers(i.children)
        }
    })
    return obj
}

console.log(JSON.stringify(treeRevers(fuza)));
console.log(JSON.stringify(data))

